// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  if (event.action == "gender") {
    return await db.collection('user')
    .doc(event.id)
    .update({
      data: {
        "gender": event.gender
      }
    })
  }
  if (event.action == "location") {
    return await db.collection('user')
    .doc(event.id)
    .update({
      data: {
        "province": event.province,
        "city": event.city
      }
    })
  }
  if (event.action == "name") {
    return await db.collection('user')
    .doc(event.id)
    .update({
      data: {
        "nickName": event.name,
        "videos.$[].name": event.name 
      }
    })
  }
  if (event.action == "intro") {
    return await db.collection('user')
    .doc(event.id)
    .update({
      data: {
        "intro": event.intro
      }
    })
  }
}